//配置axios的前缀
axios.defaults.baseURL='http://localhost:8080/'
//把axios配置为全局变量
Vue.prototype.$http = axios //给Vue这个类添加一个原型的属性,这个类的对象都能调用
//屏蔽vue的警告
Vue.config.productionTip = false

function parseUrlParams2Obj(url){// http://bugtracker.itsource.cn/callback.html?code=061IduGa1839qC02jlIa1NmHxX1IduGX&state=1
  //获取请求参数
  let paramStr = url.substring(url.indexOf("?")+1);//code=021FdXFa14mYlA016OGa1L3R4X0FdXFO&state=1
  let paramStrs = paramStr.split("&");//[code=021FdXFa14mYlA016OGa1L3R4X0FdXFO,state=1]
  let paramObj = {};
  for(let i=0;i<paramStrs.length;i++){
    let paramName = paramStrs[i].split("=")[0];//code
    let paramValue = paramStrs[i].split("=")[1];//021FdXFa14mYlA016OGa1L3R4X0FdXFO
    paramObj[paramName] = paramValue;// 动态给对象设置属性和值
  }
  return paramObj;
}
//前置拦截器
axios.interceptors.request.use(config=>{
  //携带token  获取本地的token
  let token =  localStorage.getItem("token");
  console.log(token)
  if(token){
    config.headers['ToKen']=token;
  }
  return config;
},error => {
  Promise.reject(error);
})
